/*
 * Flashlib - QB9 common Flash library
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.qb9.flashlib.lang
{
	/**
	 * Perform a given action on all elements of an Array or Object.
	 *
	 * <p>This function seems equal to <code>([1,3,3]).forEach(function(num:int, index:int, arr:Array) : void { });</code>
	 * The difference is that it only passes the value (and optionally the index).
	 * This is, in general, the desired behavior. It also supports literal objects.</p>
	 * 
	 * @see http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/Array.html#forEach()
	 */
	public function foreach(obj:Object, fn:Function, ...args:Array) : void
	{
		for each(var value:Object in obj)
			fn.apply(null, [value].concat(args));
	}
}
